package com.kuang.controller;

import com.kuang.mapper.UserMapper;
import com.kuang.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @program: springboot-05-mybatis
 * @description:
 * @author: 陈恩涛
 * @create: 2020-10-27 07:19
 **/

@RestController
public class UserController {

    @Autowired
    private UserMapper userMapper;

    @GetMapping("/queryUserList")
    public List<User> queryUserList(){
        List<User> userList = userMapper.queryUserList();

        for (User user : userList) {
            System.out.println(user);
        }

        return userList;
    }

    @GetMapping("/queryUserById/{id}")
    public User queryUserById(@PathVariable("id") Integer id){
        User user = userMapper.queryUserById(id);
        return user;
    }

    @GetMapping("/addUser")
    public int addUser(){
        User user = new User(5, "小智", "pikachu");
        return userMapper.addUser(user);
    }

    @GetMapping("/updateUser")
    public int updateUser(){
        return userMapper.updateUser(new User(5,"格拉吉欧","银伴战兽"));
    }

    @GetMapping("/deleteUser/{id}")
    public int deleteUser(@PathVariable("id") Integer id){
        return userMapper.deleteUser(id);
    }
}
